// Copyright (c) 2025, 大连理工大学 (Dalian University of Technology)
//
// Licensed under the Mulan PSL v2.
// You can use this file according to the terms and conditions of the Mulan PSL v2.
// You may obtain a copy of the License at
//
//     http://license.coscl.org.cn/MulanPSL2
//
// THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
// EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. SEE THE MULAN PSL v2
// FOR MORE DETAILS.

#include "Import/BDFImport/BulkData/Material/MAT8Parser.h"

#include "gtest/gtest.h"

#include "DataStructure/Common/Constant.h"

#include "DBManager/DBServiceFactory.h"
#include "DBManager/IService/Input/Material/IOrthotropic2DMaterialService.h"

#include "Import/BDFImport/BDFParserBase.h"
using namespace SG::DBManager;
using namespace SG::Import;

using SG::DataStructure::Common::TOLERANCE;
extern std::shared_ptr<DBServiceFactory> DB_SERVICEFACTORY;
extern std::vector<std::string>          dividedEntryInfo;

class MAT8ParserTest : public ::testing::Test
{
  public:
    static void SetUpTestSuite ()
    {
        std::vector<std::string> Entry = { "MAT8*    986             55158.          51710.699       .044",
                                           "*        3461.1699                                       2.283-9",
                                           "*                                                        599.84399",
                                           "*        785.72699       537.78998       565.37          261.311" };

        BDF::divideBulkEntry (Entry, dividedEntryInfo);
        SG::Import::BDF::BULKDATA::ParseMAT8 (DB_SERVICEFACTORY, dividedEntryInfo);

        Entry = { "MAT8*    464             36.900002       23.200001",
                  "*        10.                                             2.283-9" };

        BDF::divideBulkEntry (Entry, dividedEntryInfo);
        SG::Import::BDF::BULKDATA::ParseMAT8 (DB_SERVICEFACTORY, dividedEntryInfo);
    }
};

TEST_F (MAT8ParserTest, ParseEntry1)
{
    SG::DataStructure::FEM::Orthotropic2DMaterial data;

    ASSERT_TRUE (DB_SERVICEFACTORY->get<IOrthotropic2DMaterialService> ()->FindById (986, data)
                 == SG::DataStructure::Common::Status::STATUS_Success);

    ASSERT_TRUE (data.m_id == 986);
    ASSERT_TRUE (data.m_E1 == 55158.0);
    ASSERT_TRUE (data.m_E2 == 51710.699);
    ASSERT_TRUE (data.m_nu12 == 0.044);
    ASSERT_TRUE (data.m_G12 == 3461.1699);
    ASSERT_TRUE (data.m_G1Z == 0);
    ASSERT_TRUE (data.m_G2Z == 0);
    ASSERT_TRUE (data.m_rho == 2.283E-9);
    ASSERT_TRUE (data.m_XT == 599.84399);
    ASSERT_TRUE (data.m_XC == 785.72699);
    ASSERT_TRUE (data.m_YT == 537.78998);
    ASSERT_TRUE (data.m_YC == 565.37);
    ASSERT_TRUE (data.m_S == 261.311);
}

TEST_F (MAT8ParserTest, ParseEntry2)
{
    SG::DataStructure::FEM::Orthotropic2DMaterial data;

    ASSERT_TRUE (DB_SERVICEFACTORY->get<IOrthotropic2DMaterialService> ()->FindById (464, data)
                 == SG::DataStructure::Common::Status::STATUS_Success);

    ASSERT_TRUE (data.m_id == 464);
    ASSERT_TRUE (data.m_E1 == 36.900002);
    ASSERT_TRUE (data.m_E2 == 23.200001);
    ASSERT_TRUE (data.m_nu12 == 0.00);
    ASSERT_TRUE (data.m_G12 == 10.);
    ASSERT_TRUE (data.m_G1Z == 0);
    ASSERT_TRUE (data.m_G2Z == 0);
    ASSERT_TRUE (data.m_rho == 2.283E-9);
    ASSERT_TRUE (data.m_XT == 0);
    ASSERT_TRUE (data.m_XC == 0);
    ASSERT_TRUE (data.m_YT == 0);
    ASSERT_TRUE (data.m_YC == 0);
    ASSERT_TRUE (data.m_S == 0);
}
